<link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/material_media/image-upload/style.css">
{extend name="public/base" /}
{block name="style"}
<link rel="stylesheet" href="__PUBLIC__/admin/material/css/index.css?v=111141&times=111" />
<link rel="stylesheet" href="__PUBLIC__/admin/material_media/css/index.css?v=111141&times=111" />
<link rel="stylesheet" href="__PUBLIC__/admin/material/css/iconfont.css" />
<link rel="stylesheet" href="__PUBLIC__/admin/material/css/tooltipify.css"></link>
<link rel="stylesheet" href="__PUBLIC__/static/layui/css/layui.css">
<link href="/public/plugs/editor/css/toastr.min.css" rel="stylesheet">
<link rel="stylesheet" href="__PUBLIC__/admin/upload_layui/css/index.css">
{include file="material/_ali_icon" /}

<style>
    .main-box-body .navs .active {
        background: azure;
        color: #03a9f4;
        border: 1px solid #03a9f4;
        border-radius: 5px;
    }

    a {
        color: #777;
        text-decoration: none;
    }

    a:hover {
        text-decoration: none
    }

    .table tbody>tr>td {
        padding: 0px 8px;
    }

    .table-hover>tbody>tr:nth-child(odd) {
        background-color: #f9f9f9;
    }

    .table-responsive {
        min-height: 470px;
    }
    #sidebar-nav .nav>.open .submenu>li>.submenu a:before,
    #sidebar-nav .nav>.active .submenu>li>.submenu a:before {
        content: "";
    }
	.uploadify-button-text{
		position: relative;
		display: inline-block;
		cursor: pointer;
		background: #fff;
		padding: 0px 5px;
		color: #333;
		text-align: center;
		border-radius: 3px;
		overflow: hidden;
		border: 1px solid #ccc;
	}
	em{
		color: red;
	}
	.table-hover>tbody>tr>td{
		padding:8px 0px;
	}
	.toolTip{
		text-align: left;
	}
	.label{
		font-size:0.1em ;
	}
	</style>
{/block}
{block name="body"}

<div class="main-box clearfix">
	<header class="main-box-header clearfix">
		<div class="pull-right">
			{if checkAuthRule('del')}<button id="checkALL" type="button" class="btn btn-warning"> <input class="checkbox check-all" type="checkbox" style="display: inline-block;margin-top: -2px;vertical-align: middle;"> 全选 </button>{/if}
			
			<button type="button" class="btn btn-primary" id="createUrl">
				<i class="fa fa-plus"></i> 添加音频<span class="caret"></span>
			</button>
			{if checkAuthRule('del')}<button class="btn btn-danger ajax-post confirm" url="{:url('del')}" target-form="ids">删 除</button>{/if}
		</div>
		<div class="row">
			<form method="get">
				
				{include file="material_media/_search2" /}
			</form>
		</div>
	</header>
	<div class="main-box-body clearfix">
		<!-- 搜索相关 -->
		<ul class="navs clearfix" style="margin: 10px 5px;">
			<li><span class="text-muted">平台：</span>
			</li>
			<li><a href="?&platform_ids={platform_id}&type={$typeid}&hot=999999" {if input('get.hot') == 999999 or !input('get.hot') }class="active"{/if}>全部</a>
			</li>
			<li><a href="?&platform_ids={platform_id}&type={$typeid}&hot=3" {if input('get.hot') == 3}class="active"{/if}>内站</a>
			</li>
			<li><a href="?&platform_ids={platform_id}&type={$typeid}&hot=4" {if input('get.hot') == 4}class="active"{/if}>外站</a>
			</li>

		</ul>
		{include file="material/_search" /}
		<div id="" class="clear"></div>
		<div class="row toolTip">
			<div class="col-md-4">
				<table class="table table-hover table-bordered">
					<thead>
						<tr>
							<th width="20px"><input class="checkbox check-all" type="checkbox" style="display:inline"></th>
							<th width="35px">序号</th>
							<th width="190px">文件名</th>
							<th width="20px">标签</th>
							<th width="70px">操作</th>
						</tr>
					</thead>
					<tbody>
						{volist name="list" id="vo" mod="3" }
						{eq name="mod" value="0"}
						<tr>
							<td><input class="ids row-selected" type="checkbox" name="id[]" value="{$vo['id']}"></td>
							<td class="title">{$vo.num}</td>
							<td class="toolTip" style="font-size: 18px;">
								{$vo.title}
							</td>
							<td onclick="editreferral(this)" data-json='{:json_encode($vo)}'>{$vo.tag_ids_zh}</td>
							<td style="">
								<a href="#" style="margin-right: 5px;" class="accept" onclick="playAudio('{$vo.content}',this)" title="{$vo.content}" >试听</a>
								<a href="JavaScript:;" onclick="downMedia('{$vo.content}',{$vo.id})"><i class="fa fa-download"></i>下载 (<span class="copyNum">{$vo['copy_click_num']}</span>) </a>
							</td>
						</tr>
						{/eq}
						{/volist}
						
					</tbody>
				</table>
			</div>
			<div class="col-md-4">
				<table class="table table-hover table-bordered">
					<thead>
						<tr>
							<th width="20px"><input class="checkbox check-all" type="checkbox" style="display:inline"></th>
							<th width="35px">序号</th>
							<th width="190px">文件名</th>
							<th width="20px">标签</th>
							<th width="70px">操作</th>
						</tr>
					</thead>
					<tbody>
						{volist name="list" id="vo" mod="3" }
						{eq name="mod" value="1"}
						<tr>
							<td><input class="ids row-selected" type="checkbox" name="id[]" value="{$vo['id']}"></td>
							<td class="title">{$vo.num}</td>
							<td class="toolTip" style="font-size: 18px;">
								{$vo.title}
							</td>
							<td onclick="editreferral(this)" data-json='{:json_encode($vo)}'>{$vo.tag_ids_zh}</td>
							<td style="">
								<a href="#" style="margin-right: 5px;" class="accept" onclick="playAudio('{$vo.content}',this)" title="{$vo.content}" >试听</a>
								<a href="JavaScript:;" onclick="downMedia('{$vo.content}',{$vo.id})"><i class="fa fa-download"></i>下载 (<span class="copyNum">{$vo['copy_click_num']}</span>) </a>
							</td>
						</tr>
						{/eq}
						{/volist}
						
					</tbody>
				</table>
			</div>
			<div class="col-md-4">
				<table class="table table-hover table-bordered">
					<thead>
						<tr>
							<th width="20px"><input class="checkbox check-all" type="checkbox" style="display:inline"></th>
							<th width="35px">序号</th>
							<th width="190px">文件名</th>
							<th width="20px">标签</th>
							<th width="70px">操作</th>
						</tr>
					</thead>
					<tbody>
						{volist name="list" id="vo" mod="3" }
						{eq name="mod" value="2"}
						<tr>
							<td><input class="ids row-selected" type="checkbox" name="id[]" value="{$vo['id']}"></td>
							<td class="title">{$vo.num}</td>
							<td class="toolTip" style="font-size: 18px;">
								{$vo.title}
							</td>
							<td onclick="editreferral(this)" data-json='{:json_encode($vo)}'>{$vo.tag_ids_zh}</td>
							<td style="">
								<a href="#" style="margin-right: 5px;" class="accept" onclick="playAudio('{$vo.content}',this)" title="{$vo.content}" >试听</a>
								<a href="JavaScript:;" onclick="downMedia('{$vo.content}',{$vo.id})"><i class="fa fa-download"></i>下载 (<span class="copyNum">{$vo['copy_click_num']}</span>) </a>
							</td>
						</tr>
						{/eq}
						{/volist}
					
					</tbody>
				</table>
			</div>
		</div>	
		<audio style="display: none;" src="" id="oAudio"></audio>
			{$page}
	</div>
</div>

<div class="modal fade" id="create-referral-link-modal">
	<div class="modal-dialog" role="document">
	   <div class="modal-content">
		   <div class="modal-header">
			   <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
			   <span style="font-size: 20px;"><span id="referralname">添加</span></span>
		   </div>
			<div class="modal-body">
				<div data-bind="visible: loading" class="loading-panel" style="display: none;">
					<i class="fa fa-spin fa-spinner"></i>
				</div>
				<form class="form-horizontal modelform">
					<div class="form-group models">
						<label class="control-label col-sm-2">平台</label>
						<div class="col-sm-10">
					
							<label class="radio-inline">
											<input type="checkbox" name="hot" value="3"> <span>内站</span>

							</label>
							<label class="radio-inline">
											<input type="checkbox" name="hot" value="4"> <span>外站</span>

							</label>
					
						</div>
		 			</div>

					{include file="material_media/_from_bgm" /}
					<div class="form-group">
						<label class="control-label col-sm-2">标题</label>
						<div class="col-sm-8">
							<input type="text" class="form-control"  id="audio_title"  name="title" value=""  placeholder="多个文件时以英文,分开"/>
						</div>
					</div>

					<div class="form-group">
						<label class="control-label col-sm-2">音频</label>
						<input type="hidden" class="layui-input content" name="content" id="audio_content">
						<!-- <input type="hidden" class="layui-input content" name="title" id="audio_title"> -->
						<div class="col-lg-9">
							<button type="button" class="btn btn-primary" id="audio_btn">上传</button>
							<div class="layui-upload-list">
							</div>
						</div>
					</div>
			   </form>
			</div>
		   <div class="modal-footer">
			   <button type="button" id="createreferral" class="btn btn-primary ">提交</button>
		   </div>
	   </div>
   </div>
</div>

{include file="adsmaterialbook/_from" /}
{/block}
{block name="script"}
<script src="__PUBLIC__/admin/material/js/jquery-tooltipify.min.js"></script>
<script src="/public/plugs/editor/toastr.min.js"></script>
<script type="text/javascript">

</script>

<script type="text/javascript" src="__PUBLIC__/plugs/layer/layer.js"></script>
<script type="text/javascript" src="__PUBLIC__/plugs/webuploader/webuploader.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/plugs/webuploader/webuploader.custom.js"></script>

<script type="text/javascript">

$(function() {
	$('#createUrl').on('click',function(){
		var is_rule = '{:checkAuthRule("add")}';
		if(!is_rule){
			layer.msg("你没权限添加");
			return;
		}
		var $modal = $('#create-referral-link-modal');
		$modal.on('shown.bs.modal', function () {
			//默认选择外
			multipleInput('{:stristr($action, "inside")?3:4}'.split(','),$("input:checkbox[name=hot]"));
		});	
		$modal.modal({backdrop: 'static', keyboard: false});
	});
	$("#createreferral").on('click',function(){
		var data = $('.modelform').serializeJson();
		console.log(data);
		if (data['content'].length==0 && $("#field_ebook").val() == '') {
			updateAlert("不能为空", 'danger');
			return false;
		}
		var url = "{:url('add')}";
		$.ajax({
			type: "POST",
			url: url,
			data:data,
			dataType: "json",
			success: function(data){
				if(data.code==1){
					updateAlert(data.msg, 'success');
					setTimeout(function() {	
						window.location.reload();
					}, 100);
				}else{
					updateAlert("添加，"+data.msg, 'danger');
				}
			},
			error : function(e){
				console.log(e.status);
				console.log(e.responseText);
			}
		})
	});
});

function playAudio(url,elem){
	var audioDom = $('#oAudio')[0];
	let tests = $(elem).text()
	$.each($('table td a'),function(index,value){
		if($(value).hasClass('accept')){
			$(value).text('试听')
		}
	})
	if(tests == '试听'){
		$(elem).text('暂停')
		audioDom.src = url;
		audioDom.play()
	}else{
		$(elem).text('试听')
		audioDom.pause()
	}
}
</script>
{include file="material/pub_footer"}
{include file="material_media/_pub_upload"}
{/block}